﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Spring.Transaction.Interceptor;

using BOSS.Domain.Security;
using BOSS.Domain.Warehouses;
using BOSS.Dao.Warehouses;
using BOSS.Service.Warehouses;
using BOSS.Service.Security;

namespace BOSS.Service.Implements.Warehouses
{
    /// <summary>
    /// 仓库服务
    /// </summary>
    public class WarehouseService : EntityService<Warehouse, int, IWarehouseDao>, IWarehouseService
    {
        /// <summary>
        /// 获取 / 设置 账户服务
        /// </summary>
        public IAccountService AccountService { get; set; }
                 
        /// <summary>
        /// 保存或修改仓库
        /// </summary>
        /// <param name="entity"></param>
        [Transaction(ReadOnly=false)]
        public override void SaveOrUpdate(Warehouse entity)
        {
            this.Prepare(entity);
            base.SaveOrUpdate(entity);
        }

        private void Prepare<T>(T entity) where T : DomainEntity<int>
        {
            DateTime now = DateTime.Now;
            if (entity.Id == 0)
            {
                entity.Creator = this.AccountService.CurrentAccount;
                ;
                entity.CreateTime = now;
            }
            entity.Updator = this.AccountService.CurrentAccount;
            entity.UpdateTime = now;
        }
    }
}
